package cn.vic.model;

import cn.vic.db.model.Table;
import cn.vic.util.StringUtils;
import com.alibaba.fastjson.JSON;

import java.sql.Connection;
import java.util.*;

/**
 * Created by vic on 2017/8/9.
 */
public class RepidModel {

    private String jdbcUsername;
    private String jdbcPassword;
    private String jdbcUrl;
    private String jdbcDriver;
    private Connection connection;

    private String tableName;
    private String packages;
    private String module;
    private Map<String, Object> customParam;
    private String templatePath;
    private String savePath;
    private boolean cover;


    private List<Table> tableModels = new ArrayList<>();

    public String getJdbcUsername() {
        return jdbcUsername;
    }

    public void setJdbcUsername(String jdbcUsername) {
        this.jdbcUsername = jdbcUsername;
    }

    public String getJdbcPassword() {
        return jdbcPassword;
    }

    public void setJdbcPassword(String jdbcPassword) {
        this.jdbcPassword = jdbcPassword;
    }

    public String getJdbcUrl() {
        return jdbcUrl;
    }

    public void setJdbcUrl(String jdbcUrl) {
        this.jdbcUrl = jdbcUrl;
    }

    public String getJdbcDriver() {
        return jdbcDriver;
    }

    public void setJdbcDriver(String jdbcDriver) {
        this.jdbcDriver = jdbcDriver;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getPackages() {
        return packages;
    }

    public void setPackages(String packages) {
        this.packages = packages;
    }

    public String getTemplatePath() {
        return templatePath;
    }

    public void setTemplatePath(String templatePath) {
        this.templatePath = templatePath;
    }

    public String getSavePath() {
        return savePath;
    }

    public void setSavePath(String savePath) {
        this.savePath = savePath;
    }

    public List<Table> getTableModels() {
        return tableModels;
    }

    public void setTableModels(List<Table> tableModels) {
        if (tableModels == null && tableModels.size() == 0) {
            throw new NullPointerException("参数异常");
        }
        this.tableModels.addAll(tableModels);
    }

    public void setTableModels(Table... tableModels) {
        if (tableModels == null && tableModels.length == 0) {
            throw new NullPointerException("参数异常");
        }
        this.tableModels.addAll(Arrays.asList(tableModels));
    }

    public Connection getConnection() {
        return connection;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public Map<String, Object> getCustomParam() {
        return customParam;
    }

    public void setCustomParam(Map<String, Object> customParam) {
        this.customParam = customParam;
    }

    public boolean isCover() {
        return cover;
    }

    public void setCover(boolean cover) {
        this.cover = cover;
    }

    public void addCustomParam(String param) {
        if (customParam == null) {
            customParam = new HashMap<>();
        }
        if (StringUtils.isNotBlank(param)) {
            try {
                customParam.putAll(JSON.parseObject(param));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
